/*
 * @Author: Jian SuiYue kaohx0214@yeah.net
 * @Date: 2025-06-04 08:05:34
 * @LastEditTime: 2025-06-06 22:55:07
 * @FilePath: src/main/java/com/tencent/wxcloudrun/convert/MyTypeHandler.java
 */
package com.tencent.wxcloudrun.convert;

import com.tencent.wxcloudrun.model.BaseEnum;
import com.tencent.wxcloudrun.model.BookStatus;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.TypeHandler;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.HashMap;

@MappedJdbcTypes(JdbcType.CHAR)
public class MyTypeHandler<T extends Enum<T> & BaseEnum> implements TypeHandler<String> {
    
    private HashMap<Character, String> enumMap = new HashMap<>();
    
    public MyTypeHandler(Class<T> enumType) {
        // initial the enumMap
        Arrays.stream(enumType.getEnumConstants())
                .forEach(x -> {
                    enumMap.put(x.getCode(), x.getDesc());
                });
    }

    @Override
    public void setParameter(PreparedStatement preparedStatement, int i, String s, JdbcType jdbcType) throws SQLException {
        
    }

    @Override
    public String getResult(ResultSet resultSet, String s) throws SQLException {
//        Character c = resultSet.getCharacterStream(s);
        return "";
    }

    @Override
    public String getResult(ResultSet resultSet, int i) throws SQLException {
        return "";
    }

    @Override
    public String getResult(CallableStatement callableStatement, int i) throws SQLException {
        return "";
    }
}
